package everydayUserIdDatas

import (
	"gorm.io/gorm"
	"h_rpcx/until"
	"time"
)

type EverydayUserIdData struct {
	Id                 int32      `json:"id" gorm:"column:id"`
	Time               time.Month `json:"time" gorm:"column:time"`
	LiveMoney          float64    `json:"live_money" gorm:"column:live_money"`
	AdMoney            float64    `json:"ad_money" gorm:"column:ad_money"`
	ShopMoney          float64    `json:"shop_money" gorm:"column:shop_money"`
	TotalMoney         float64    `json:"total_money" gorm:"column:total_money"`
	FansRaise          int16      `json:"fans_raise" gorm:"column:fans_raise"`
	PlayNewRaise       int16      `json:"play_new_raise" gorm:"column:play_new_raise"`
	NewLikeNum         int16      `json:"new_like_num" gorm:"column:new_like_num"`
	CommentNum         int16      `json:"comment_num" gorm:"column:comment_num"`
	NewShareNum        int16      `json:"new_share_num" gorm:"column:new_share_num"`
	PhotoCnt           int16      `json:"photo_cnt" gorm:"column:photo_cnt"`
	LiveTime           int16      `json:"live_time" gorm:"column:live_time"`
	LiveTimeVaild      int16      `json:"live_time_vaild" gorm:"column:live_time_vaild"`
	AdOrder            int16      `json:"ad_order" gorm:"column:ad_order"`
	ShopSales          float64    `json:"shop_sales" gorm:"column:shop_sales"`
	ShopOrder          int16      `json:"shop_order" gorm:"column:shop_order"`
	ShopGold           float64    `json:"shop_gold" gorm:"column:shop_gold"`
	LiveSum            int16      `json:"live_sum" gorm:"column:live_sum"`
	LiveSumVaild       int16      `json:"live_sum_vaild" gorm:"column:live_sum_vaild"`
	LiveMoneyVaild     float64    `json:"live_money_vaild" gorm:"column:live_money_vaild"`
	AddAnchor          int16      `json:"add_anchor" gorm:"column:add_anchor"`
	AddAnchorVaild     int16      `json:"add_anchor_vaild" gorm:"column:add_anchor_vaild"`
	AddAnchorLiveMoney float64    `json:"add_anchor_live_money" gorm:"column:add_anchor_live_money"`
	LiveIds            string     `json:"live_ids" gorm:"column:live_ids"`
	LiveIdsVaild       string     `json:"live_ids_vaild" gorm:"column:live_ids_vaild"`
	SignNum            int16      `json:"sign_num" gorm:"column:sign_num"`
	UserId             int16      `json:"user_id" gorm:"column:user_id"`
	CreatedAt          time.Time  `json:"created_at" gorm:"column:created_at"`
	UpdatedAt          time.Time  `json:"updated_at" gorm:"column:updated_at"`
	DeletedAt          time.Time  `json:"deleted_at" gorm:"column:deleted_at"`
}

func (*EverydayUserIdData) TableName() string {
	return "hx_everyday_userid_datas"
}

func NewEverydayUserIdData() *EverydayUserIdData {
	return &EverydayUserIdData{}
}

//我的艺人流水
func (*EverydayUserIdData) MyArtistWater(db *gorm.DB, uid int32) (map[string]float32, error) {
	m := make(map[string]float32)
	//上个月时间
	ti := until.FirstAndLast(time.Now())
	//这个月1号和当前的时间
	now := until.ThisMonthFirstToNow(time.Now())
	var this_moth_sum float32
	var last_moth_sum float32
	err := db.Model(&EverydayUserIdData{}).
		Where("time > ? and time < ?", now["first_day"], now["last_day"]).Where("user_id = ?", uid).Where("deleted_at is null").
		Pluck("sum(total_money)", &this_moth_sum).Error
	err = db.Model(&EverydayUserIdData{}).
		Where("time > ? and time < ?", ti["first_day"], ti["last_day"]).Where("user_id = ?", uid).Where("deleted_at is null").
		Pluck("sum(total_money)", &last_moth_sum).Error
	if err != nil {
		return nil, err
	}
	m["this_moth_sum"] = this_moth_sum
	m["last_moth_sum"] = last_moth_sum
	return m, nil
}
